<?php
namespace app\modules\adminapi\controllers;

use fate\http\Request;
use app\models\UserLevel;
use app\libs\Util;

class AddlevelController extends \app\modules\adminapi\ForceLoginPure {

    public function run() {
        $req = Request::getInstance();

        $levelName = Util::plainText($req->getParameter('level_name'));
        $minExp = Util::plainText($req->getParameter('minexp'));
        $maxExp = Util::plainText($req->getParameter('maxexp'));
        $levelNum = Util::plainText($req->getParameter('level_num'));

        if(!$levelName) {
            $this->ajaxReturn(null, 300002);
            exit;
        }
        if(!is_numeric($minExp) || !is_numeric($maxExp) || !is_numeric($levelNum)) {
            $this->ajaxReturn(null, 300002);
            exit;
        }

        $data = [
            'level_name' => $levelName,
            'minexp' => $minExp,
            'maxexp' => $maxExp,
            'level_num' => $levelNum
        ];
        // var_dump($data);exit;

        $model = new UserLevel();
        $ret = $model->insert($data);

        $this->ajaxReturn(null);
    }

}
